#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=3e4+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],c[5],cnt[5];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL t;cin>>t;
  while(t--){
    memset(c,0,sizeof(c));memset(cnt,0,sizeof(cnt));
    LL n;cin>>n;
    for(LL i=1;i<=n;i++) cin>>a[i],c[a[i]%3]++;
    LL f=n/3;
   /// debug(f);
   /// for(LL i=0;i<3;i++) cout<<c[i]<<" ";
   /// cout<<"\n";
    for(LL i=0;i<3;i++)  cnt[i]=c[i]-f;
    LL ans=0;
    for(LL i=0;i<3;i++){
        if(cnt[i]>0){
            for(LL j=0;j<3;j++){
                if(i==j) continue;
                if(cnt[j]<0){
                    LL k=min(abs(cnt[i]),abs(cnt[j]));
                    cnt[i]-=k;cnt[j]+=k;
                    if(i==0&&j==1) ans+=k*1;
                    if(i==0&&j==2) ans+=k*2;
                    if(i==1&&j==2) ans+=k*1;
                    if(i==1&&j==0) ans+=k*2;
                    if(i==2&&j==0) ans+=k*1;
                    if(i==2&&j==1) ans+=k*2;
                }
            }
        }
    }
    cout<<ans<<"\n";
    ///LL ans=0;
    /*
    if(c[0]>=c[1]&&c[0]>=c[2]){
        LL d1=f-c[1];LL d2=f-c[2];
        ans=d1+2*d2;
    }
    else if(c[1]>=c[0]&&c[1]>=c[2]){
        LL d1=f-c[0];LL d2=f-c[2];
        ans=2*d1+d2;
    }
    else if(c[2]>=c[0]&&c[2]>=c[1]){
        LL d1=f-c[0];LL d2=f-c[1];
        ans=d1+2*d2;
    }
    cout<<ans<<"\n";*/
  }
return 0;
}
